package com.system.controller;

import com.system.exception.CustomException;
import com.system.po.Userlogin;
import com.system.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;


@Controller
@RequestMapping("/admin")
@Api(value = "/admin", tags = "admin接口")
public class AdminController {





    @Resource(name = "userloginServiceImpl")
    private UserloginService userloginService;


    @RequestMapping("/showEmer")
    public String Emer() throws Exception {
        return "admin/showEmer";
    }



    @RequestMapping("/showPlan")
    public String showPlan() throws Exception {
        return "admin/showPlan";
    }


    @RequestMapping("/showSpecial")
    public String showSpecial() throws Exception {
        return "admin/showSpecial";
    }


    @RequestMapping("/showDirect")
    public String showDirect() throws Exception {
        return "admin/showDirect";
    }



    // 普通用户账号密码重置
    @RequestMapping("/userPasswordRest")
    public String userPasswordRestUI() throws Exception {
        return "admin/userPasswordRest";
    }

    // 普通用户账号密码重置处理
    @RequestMapping(value = "/userPasswordRest", method = {RequestMethod.POST})
    public String userPasswordRest(Userlogin userlogin) throws Exception {

        Userlogin u = userloginService.findByName(userlogin.getUsername());

        if (u != null) {
            if (u.getRole() == 0) {
                throw new CustomException("该账户为管理员账户，没法修改");
            }
            u.setPassword(userlogin.getPassword());
            userloginService.updateByName(userlogin.getUsername(), u);
        } else {
            throw new CustomException("没找到该用户");
        }

        return "admin/userPasswordRest";
    }

    // 本账户密码重置
    @RequestMapping("/passwordRest")
    public String passwordRestUI() throws Exception {
        return "admin/passwordRest";
    }

    // 转发应急预案
    @RequestMapping( value = "/contingencyPlan")
    @ApiOperation(value = "转发应急预案")
    @ResponseBody
    public ModelAndView drawing() throws Exception {
        ModelAndView mv2=new ModelAndView();
        mv2.setViewName("admin/contingencyPlan");
        return mv2;
    }



    // 转发应急预案增加节点
    @RequestMapping( value = "/add1edit/{id}")
    @ApiOperation(value = "转发应急预案")
    @ResponseBody
    public ModelAndView add1edit(@PathVariable("id") Integer id) throws Exception {
        String code= String.valueOf(id);
        ModelAndView mv2=new ModelAndView();
        mv2.addObject("code",code);
        mv2.setViewName("admin/add1edit");
        return mv2;
    }


    // 转发应急预案增加兄弟节点
    @RequestMapping( value = "/add2edit")
    @ApiOperation(value = "转发应急预案")
    @ResponseBody
    public ModelAndView add2edit() throws Exception {
        ModelAndView mv2=new ModelAndView();
        mv2.setViewName("admin/add2edit");
        return mv2;
    }


    // 转发应急预案编辑兄弟节点
    @RequestMapping( value = "/editedit/{id}")
    @ApiOperation(value = "转发应急预案")
    @ResponseBody
    public ModelAndView editedit(@PathVariable("id") Integer id) throws Exception {
        String code= String.valueOf(id);
        ModelAndView mv2=new ModelAndView();
        mv2.addObject("code",code);
        mv2.setViewName("admin/editedit");
        return mv2;
    }


    // 转发应急预案编辑子节点
    @RequestMapping( value = "/edit2edit/{id}")
    @ApiOperation(value = "转发应急预案")
    @ResponseBody
    public ModelAndView edit2edit(@PathVariable("id") Integer id) throws Exception {
        String code= String.valueOf(id);
        ModelAndView mv2=new ModelAndView();
        mv2.addObject("code",code);
        mv2.setViewName("admin/edit2edit");
        return mv2;
    }

    // 转发事故处理
    @RequestMapping( value = "/troubleRemoval")
    @ApiOperation(value = "转发应急预案")
    @ResponseBody
    public ModelAndView troubleRemoval() throws Exception {
        ModelAndView mv2=new ModelAndView();
        mv2.setViewName("admin/troubleRemoval");
        return mv2;
    }

    // 转发事故处理事故信息
    @RequestMapping( value = "/accidentInformation")
    @ApiOperation(value = "事故信息")
    @ResponseBody
    public ModelAndView accidentInformation() throws Exception {
        ModelAndView mv2=new ModelAndView();
        mv2.setViewName("admin/accidentInformation");
        return mv2;
    }


    // 转发事故处理人员通知
    @RequestMapping( value = "notifiesThe")
    @ApiOperation(value = "人员通知")
    @ResponseBody
    public ModelAndView notifiesThe() throws Exception {
        ModelAndView mv2=new ModelAndView();
        mv2.setViewName("admin/notifiesThe");
        return mv2;
    }


    // 转发事故处理相关文档
    @RequestMapping( value = "/relatedDocuments")
    @ApiOperation(value = "相关文档")
    @ResponseBody
    public ModelAndView relatedDocuments() throws Exception {
        ModelAndView mv2=new ModelAndView();
        mv2.setViewName("admin/relatedDocuments");
        return mv2;
    }


    // 转发事系统设置
    @RequestMapping( value = "/systemSettings")
    @ApiOperation(value = "系统设置")
    @ResponseBody
    public ModelAndView systemSettings() throws Exception {
        ModelAndView mv2=new ModelAndView();
        mv2.setViewName("admin/systemSettings");
        return mv2;
    }


    // 转发事系统设置指挥部
    @RequestMapping( value = "/headquarters")
    @ApiOperation(value = "指挥部")
    @ResponseBody
    public ModelAndView headquarters() throws Exception {
        ModelAndView mv2=new ModelAndView();
        mv2.setViewName("admin/headquarters");
        return mv2;
    }


    // 转发事系统管理
    @RequestMapping( value = "/systemManagement")
    @ApiOperation(value = "系统管理")
    @ResponseBody
    public ModelAndView systemManagement() throws Exception {
        ModelAndView mv2=new ModelAndView();
        mv2.setViewName("admin/systemManagement");
        return mv2;
    }

    // 转发事系统管理角色权限
    @RequestMapping( value = "/role_basedAccessControl")
    @ApiOperation(value = "角色权限")
    @ResponseBody
    public ModelAndView role_basedAccessControl() throws Exception {
        ModelAndView mv2=new ModelAndView();
        mv2.setViewName("admin/role_basedAccessControl");
        return mv2;
    }
    // 转发事增加文档
    @RequestMapping( value = "/relatedDocumentsadd")
    @ApiOperation(value = "增加文档")
    @ResponseBody
    public ModelAndView relatedDocumentsadd() throws Exception {
        ModelAndView mv2=new ModelAndView();
        mv2.setViewName("admin/relatedDocumentsadd");
        return mv2;
    }

    // 转发编辑文档
    @RequestMapping( value = "/relatedDocumentsedit/{id}")
    @ApiOperation(value = "编辑")
    @ResponseBody
    public ModelAndView relatedDocumentsedit(@PathVariable("id") Integer id) throws Exception {
        String code= String.valueOf(id);
        ModelAndView mv2=new ModelAndView();
        mv2.addObject("code",code);
        mv2.setViewName("admin/relatedDocumentsedit");
        return mv2;
    }
    // 转发用户
    @RequestMapping( value = "/adduser1")
    @ApiOperation(value = "转发用户")
    @ResponseBody
    public ModelAndView adduer1() throws Exception {
        ModelAndView mv2=new ModelAndView();
        mv2.setViewName("admin/adduser");
        return mv2;
    }
    // 转发用户列表
    @RequestMapping( value = "/userlist")
    @ApiOperation(value = "用户列表")
    @ResponseBody
    public ModelAndView userlist() throws Exception {
        ModelAndView mv2=new ModelAndView();
        mv2.setViewName("admin/userlist");
        return mv2;
    }
    // 转发编辑指挥部
    @RequestMapping( value = "/editorialHeadquarters/{id}")
    @ApiOperation(value = "编辑指挥部")
    @ResponseBody
    public ModelAndView editorialHeadquarters(@PathVariable("id") Integer id) throws Exception {
        String code= String.valueOf(id);
        ModelAndView mv2=new ModelAndView();
        mv2.addObject("code",code);
        mv2.setViewName("admin/editorialHeadquarters");
        return mv2;
    }

    // 转发增加指挥部
    @RequestMapping( value = "/addCommandPost")
    @ApiOperation(value = "增加指挥部")
    @ResponseBody
    public ModelAndView addCommandPost() throws Exception {
        ModelAndView mv2=new ModelAndView();
        mv2.setViewName("admin/addCommandPost");
        return mv2;
    }
}
